<template>
	<view class="">
		<span class="phone">电话号码</span>

		
		
		        <view class="popup-content">
		            <view class="group">
		                <input class="uni-input" type="tel" v-model="validMobile.phonenumber" placeholder="手机号" />
		            </view>
		            <view class="group">
		                <input class="uni-input" v-model="obj.captcha" placeholder="验证码" />
		                <text class="valid-text" @click="countdownChange">{{countdown.validText}}</text>
		            </view>
		        </view>
				<view class="">
					<button @click="register">登录</button>
				</view>

	</view>
</template>
<script setup>
	import {ref,reactive,computed,onMounted } from 'vue'
	import { onLoad } from '@dcloudio/uni-app'
	import { captchaSms,loginApp,loginGetInfo } from '@/common/js/api.js'
	const app = getApp()
	
	
	// 验证码
	const countdown = reactive({
		validText:'获取验证码',
		time:60,
	})
	// 手机验证
	const validMobile = reactive({
		countryCode:86,
		phonenumber:'',
	})

	const obj = reactive({
		captcha:'',//短信验证码
		code:'',
		countryCode:'86',//国家码
		merchantId:0,
		mobile:'',
		password:'',//密码
		 get phone() {
		        return Number(validMobile.phonenumber);
		    },
	})

	

	// 手机号验证
	let flag = false
	const countdownChange=()=>{
		console.log(validMobile.phonenumber,'>>>>>获取验证码')
		if(!validMobile.phonenumber){
			return uni.showToast({
				title:'请填写手机号',
				icon:'none',
				duration:1000
			})
		}
		// 获取验证码
		captchaSms({...validMobile}).then((res) => {
		
			})
		if(flag) return
		const time = setInterval(()=>{
			if(countdown.time<=0){
				countdown.validText = '获取验证码'
				countdown.time = 60
				flag = false
				// 清楚定时器
				clearInterval(time)
			}else{
				countdown.time -= 1
				countdown.validText = `剩余${countdown.time}s `
			}
		},1000)
		
		flag = true
	}
	const register=()=>{
		console.log(11)
		loginApp({...obj}).then((res)=>{
		})
		// loginRoutine
		setTimeout(function(){
			console.log('dasda1')
			sloginGetInfo()
		},1000)
		
	}
	
	const sloginGetInfo=()=>{
	
		loginGetInfo().then((res)=>{
			console.log(res,'用户信息')
			const data = res.data
			// return
			uni.setStorageSync('userInfo',data)
			uni.switchTab({	url: '/pages/me/index'	});
		})
		// loginRoutine
	}
	
	
	onLoad(()=>{

	})
</script>
<style lang="scss">
	.phone{
		margin: 12px;
		    font-size: 16px;
		    font-weight: 800;
	}
	.group{
		display: flex;
	}
	
</style>
